package com.jsyh.maidu.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jsyh.maidu.R;
import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.model.Stores;
import com.jsyh.shopping.uilibrary.views.CircleImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 */

public class ComprehensiveAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<Stores> datas;

    public ComprehensiveAdapter(Context context, List<Stores> datas) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.gv_item_jptj, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.bindData(datas.get(i));

        return view;
    }

    class ViewHolder{
        private CircleImageView iv_goodsIcon;
        private TextView tv_goodsInfo;

        public ViewHolder(View view) {
            iv_goodsIcon = (CircleImageView) view.findViewById(R.id.iv_goodsIcon);
            tv_goodsInfo = (TextView) view.findViewById(R.id.tv_goodsInfo);
        }

        public void bindData(Stores stores) {
            Picasso.with(context).load(ConfigValue.IMG_IP + stores.getLogo()).into(iv_goodsIcon);

            tv_goodsInfo.setText(stores.getSupplier_name());
        }

    }
}
